package session1.whatIsIt;

import javax.swing.*;
import java.awt.*;

class StudentSurveyForm extends JFrame {
	 public StudentSurveyForm() {
		 setTitle("大学生个人信息调查问卷");
		 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		 setResizable(true);

		 JPanel mainPanel = new JPanel();
		 mainPanel.setLayout(new GridBagLayout());
		 GridBagConstraints gbc = new GridBagConstraints();
		 gbc.insets = new Insets(3, 5, 3, 10);
		 INIT:
		 {


			 // 第一部分：基本信息
			 JLabel nameLabel = new JLabel("姓名:");
			 gbc.gridx = 0;
			 gbc.gridy = 0;
			 mainPanel.add(nameLabel, gbc);

			 JTextField nameField = new JTextField(10);
			 gbc.gridx = 1;
			 gbc.gridy = 0;
			 mainPanel.add(nameField, gbc);

			 JLabel studentIdLabel = new JLabel("学号:");
			 gbc.gridx = 0;
			 gbc.gridy = 1;
			 mainPanel.add(studentIdLabel, gbc);

			 JTextField studentIdField = new JTextField(10);
			 gbc.gridx = 1;
			 gbc.gridy = 1;
			 mainPanel.add(studentIdField, gbc);

			 JLabel genderLabel = new JLabel("性别:");
			 gbc.gridx = 0;
			 gbc.gridy = 2;
			 mainPanel.add(genderLabel, gbc);

			 ButtonGroup genderGroup = new ButtonGroup();
			 JRadioButton maleRadioButton = new JRadioButton("男");
			 JRadioButton femaleRadioButton = new JRadioButton("女");
			 genderGroup.add(maleRadioButton);
			 genderGroup.add(femaleRadioButton);

			 JPanel genderPanel = new JPanel();
			 genderPanel.add(maleRadioButton);
			 genderPanel.add(femaleRadioButton);
			 gbc.gridx = 1;
			 gbc.gridy = 2;
			 mainPanel.add(genderPanel, gbc);

			 // 第二部分：学业信息
			 JLabel departmentLabel = new JLabel("院系:");
			 gbc.gridx = 0;
			 gbc.gridy = 3;
			 mainPanel.add(departmentLabel, gbc);

			 String[] departments = {"光电学院", "管理学院", "外语学院", "机械学院", "传播学院"};
			 JComboBox<String> departmentComboBox = new JComboBox<>(departments);
			 gbc.gridx = 1;
			 gbc.gridy = 3;
			 mainPanel.add(departmentComboBox, gbc);

			 JLabel majorLabel = new JLabel("专业:");
			 gbc.gridx = 0;
			 gbc.gridy = 4;
			 mainPanel.add(majorLabel, gbc);

			 String[] majors = {"计算机科学与技术", "大数据", "自动化", "光电信息", "新闻学", "金融学", "管理科学", "汽车工程", "英语", "日语"};
			 JList<String> majorList = new JList<>(majors);
			 majorList.setVisibleRowCount(4);
			 JScrollPane majorScrollPane = new JScrollPane(majorList);
			 gbc.gridx = 1;
			 gbc.gridy = 4;
			 mainPanel.add(majorScrollPane, gbc);

			 JLabel courseLabel = new JLabel("所选课程:");
			 gbc.gridx = 0;
			 gbc.gridy = 5;
			 mainPanel.add(courseLabel, gbc);

			 String[] courses = {"高等数学", "Java编程", "数据库", "数据结构", "经济学", "大学物理", "大学英语"};
			 JCheckBox[] courseCheckBoxes = new JCheckBox[courses.length];
			 JPanel coursePanel = new JPanel();
			 coursePanel.setLayout(new GridLayout(courses.length, 1));
			 for (int i = 0; i < courses.length; i++) {
				 courseCheckBoxes[i] = new JCheckBox(courses[i]);
				 coursePanel.add(courseCheckBoxes[i]);
			 }
			 gbc.gridx = 1;
			 gbc.gridy = 5;
			 mainPanel.add(coursePanel, gbc);

			 // 第三部分：其他情况
			 JLabel interestLabel = new JLabel("个人兴趣爱好:");
			 gbc.gridx = 0;
			 gbc.gridy = 6;
			 mainPanel.add(interestLabel, gbc);

			 String[] interests = {"音乐", "体育", "旅游", "阅读"};
			 JCheckBox[] interestCheckBoxes = new JCheckBox[interests.length];
			 JPanel interestPanel = new JPanel();
			 interestPanel.setLayout(new GridLayout(interests.length, 1));
			 for (int i = 0; i < interests.length; i++) {
				 interestCheckBoxes[i] = new JCheckBox(interests[i]);
				 interestPanel.add(interestCheckBoxes[i]);
			 }
			 gbc.gridx = 1;
			 gbc.gridy = 6;
			 mainPanel.add(interestPanel, gbc);

			 JLabel suggestionLabel = new JLabel("对学校的建议:");
			 gbc.gridx = 0;
			 gbc.gridy = 7;
			 mainPanel.add(suggestionLabel, gbc);

			 JTextArea suggestionTextArea = new JTextArea(4, 20);
			 JScrollPane suggestionScrollPane = new JScrollPane(suggestionTextArea);
			 gbc.gridx = 1;
			 gbc.gridy = 7;
			 mainPanel.add(suggestionScrollPane, gbc);

			 // 按钮
			 JButton submitButton = new JButton("提交");
			 gbc.gridx = 0;
			 gbc.gridy = 8;
			 mainPanel.add(submitButton, gbc);

			 JButton resetButton = new JButton("重置");
			 gbc.gridx = 1;
			 gbc.gridy = 8;
			 mainPanel.add(resetButton, gbc);

			 JButton exitButton = new JButton("退出");
			 gbc.gridx = 2;
			 gbc.gridy = 8;
			 mainPanel.add(exitButton, gbc);

		 }


		 setContentPane(mainPanel);
		 pack();
		 setVisible(true);
	 }

	public static void main(String[] args) {

		SwingUtilities.invokeLater(StudentSurveyForm::new);
	}
}